//
//  MyXindeTableViewCell.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/9.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//


#import "MyXindeTableViewCell.h"
#import "LXSaveUserInforTool.h"

@interface MyXindeTableViewCell()
@property (nonatomic, strong) UIView *bacView;
@property (nonatomic, strong) UIImageView *headerImg;
@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UILabel *dateLable;
@property (nonatomic,strong) UILabel *contentLable;

@property (nonatomic,strong) NSMutableArray *imgUiarray;
@property (nonatomic,strong) NSArray*imgArray;
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UILabel *oldLabel;
@property (nonatomic,strong) UIButton *commentsBtn;
@property (nonatomic,strong) UIButton *likesBtn;

@property (nonatomic,strong) UIButton *isBlackBtn;

@end

@implementation MyXindeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self viewConfig];
    }
    return self;
}
-(void)viewConfig
{   self.selectionStyle = UITableViewCellSelectionStyleNone;

    [self.contentView addSubview:self.bacView];
    [self.bacView addSubview:self.headerImg];
    [self.bacView addSubview:self.nameLabel];
    [self.bacView addSubview:self.dateLable];
    [self.bacView addSubview:self.contentLable];
     self.imgArray = @[@"",@"",@"",@""];
    [self.bacView addSubview:self.oldLabel];
    [self.bacView addSubview:self.commentsBtn];
    [self.bacView addSubview:self.likesBtn];
   
    
}

-(UIView *)bacView{
    if (!_bacView) {
        _bacView = [[UIView alloc]initWithFrame:CGRectMake(0, TSScaleW(0), TSScreenWidth , TSScaleW(235))];
        _bacView.backgroundColor = kWhiteColor;
    }
    return _bacView;
}
-(UIImageView *)headerImg{
    if (!_headerImg) {
        _headerImg = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(11), TSScaleW(15), TSScaleW(35), TSScaleW(35))];
        [_headerImg setCornerRadius:_headerImg.height/2.f];
        _headerImg.backgroundColor = kGrayTxtColor;
 
    }
    return _headerImg;
}
-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [TSWLTools allocLabel:@"首届星洲" font:systemBoldFont(TSScaleW(13)) textColor:kMainTxtColor frame:CGRectMake(_headerImg.right + TSScaleW(11), _headerImg.top + TSScaleW(12), TSScaleW(300), TSScaleW(13)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _nameLabel;
}


-(UILabel *)dateLable{
    if (!_dateLable) {
        _dateLable = [TSWLTools allocLabel:@"1天前" font:systemFont(TSScaleW(11)) textColor:kGreenColor frame:CGRectMake(_nameLabel.left, _nameLabel.top, _nameLabel.width,TSScaleW(11)) textAlignment:(NSTextAlignmentRight)];
        
       
    }
    return _dateLable;
}
-(UILabel *)contentLable{
    if (!_contentLable) {
        _contentLable = [TSWLTools allocLabel:@"一次很好的购物体验，服务周到，物流快速，配送也很周到，卖家态度也很好~ 下次还回购~" font:systemFont(TSScaleW(14)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(10), TSScaleW(5) + _headerImg.bottom, TSScaleW(355), TSScaleW(42)) textAlignment:(NSTextAlignmentLeft)];
        _contentLable.numberOfLines = 2;
    }
    return _contentLable;
}
-(UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, _contentLable.bottom + TSScaleW(5),TSScreenWidth, TSScaleW(92))];
        
    }
    return _scrollView;
}
-(NSMutableArray *)imgUiarray{
    if (!_imgUiarray) {
        _imgUiarray = [NSMutableArray array];
    }
    return _imgUiarray;
}
-(void)setImgArray:(NSArray *)imgArray{
    _imgArray = imgArray;
    for (UIView *v in self.imgUiarray) {
        [v removeFromSuperview];
    }
    [self.imgUiarray removeAllObjects];
    for (int i = 0; i < _imgArray.count; i ++) {
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(10) + i * TSScaleW(119), 0, TSScaleW(116), TSScaleW(91))];
        img.backgroundColor = kGrayBtnBacColor;
        [img sd_setImageWithURL:[NSURL URLWithString:imgArray[i]]];
        [self.scrollView addSubview:img];
        self.scrollView.contentSize = CGSizeMake(img.right + TSScaleW(16), 0);
        [self.imgUiarray addObject:img];
        img.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        [img addGestureRecognizer:tap];
    }
    [self.contentView addSubview:self.scrollView];

}


-(void)tapAction:(UITapGestureRecognizer *)tap{
NSInteger index = [self.imgUiarray indexOfObject:tap.view];
[TSWLTools pictureSelectWithPicArr:self.imgArray withIndex:index];
}
-(UILabel *)oldLabel{
    if (!_oldLabel) {
        _oldLabel = [TSWLTools allocLabel:@"0~3岁" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(11), TSScaleW(14) + _scrollView.bottom, TSScaleW(120), TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _oldLabel;
}
-(UIButton *)commentsBtn{
    if (!_commentsBtn) {
        _commentsBtn = [TSWLTools allocButtonTitle:@"99" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor image:[UIImage imageNamed:@"pingun"] frame:CGRectMake(0, TSScaleW(14) + _scrollView.bottom, TSScaleW(60), TSScaleW(30)) sel:@selector(commentsBtnAction) taget:self];
        [_commentsBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -TSScaleW(5), 0, 0)];
        _commentsBtn.left = TSScaleW(236);
    }
    return _commentsBtn;
}
-(void)commentsBtnAction
{
    
}
-(UIButton *)likesBtn{
    if (!_likesBtn) {
        _likesBtn = [TSWLTools allocButtonTitle:@"99" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor image:[UIImage imageNamed:@"点赞_d"] frame:CGRectMake(_commentsBtn.right, _commentsBtn.top, TSScaleW(60), TSScaleW(30)) sel:@selector(likesBtnAction:) taget:self];
        [_likesBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -TSScaleW(5), 0, 0)];
    }
    return _likesBtn;
}
-(void)likesBtnAction:(UIButton *)sender
{
    
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [_headerImg sd_setImageWithURL:[NSURL URLWithString:_dataDic[@"usericon"]]];
    _nameLabel.text = _dataDic[@"username"];
    _dateLable.text = _dataDic[@"adtime"];
    _contentLable.text = _dataDic[@"content"];
    self.imgArray = _dataDic[@"images"];
//    "collectCount":"",//收藏数量
//                "shareCount":"",//分享数量
//                "commentCount":"",//评论数量
    [self.commentsBtn setTitle:_dataDic[@"commentnum"] forState:(UIControlStateNormal)];
   // [self.shareBtn setTitle:_dataDic[@"shareCount"] forState:(UIControlStateNormal)];
    [self.likesBtn setTitle:_dataDic[@"zannum"] forState:(UIControlStateNormal)];
//    NSDictionary * member = _dataDic[@"member"];
//    //_nameLabel.text = member[@"nickname"];
//   、、 [_headerImg sd_setImageWithURL:[NSURL URLWithString:member[@"avatar"]]];
  

}
-(void)setSecDic:(NSDictionary *)secDic{
    _secDic = secDic;
    [_headerImg sd_setImageWithURL:[NSURL URLWithString:_secDic[@"usericon"]]];
    _nameLabel.text = _secDic[@"username"];
    _dateLable.text = _secDic[@"adtime"];
    _contentLable.text = _secDic[@"content"];
    self.imgArray = _secDic[@"images"];
//    "collectCount":"",//收藏数量
//                "shareCount":"",//分享数量
//                "commentCount":"",//评论数量
    [self.commentsBtn setTitle:_secDic[@"commentnum"] forState:(UIControlStateNormal)];
   // [self.shareBtn setTitle:_dataDic[@"shareCount"] forState:(UIControlStateNormal)];
    [self.likesBtn setTitle:_secDic[@"zannum"] forState:(UIControlStateNormal)];
    //NSDictionary * member = _dataDic[@"member"];
    //_nameLabel.text = member[@"nickname"];
    //[_headerImg sd_setImageWithURL:[NSURL URLWithString:member[@"avatar"]]];
    self.oldLabel.text = _secDic[@"fname"];
    
    
}
-(void)setIsOn:(BOOL)isOn{
    self.isBlackBtn.hidden = _isOn;
    if (_isOn) {
       
    }else{
        [self.bacView addSubview:self.isBlackBtn];
        _dateLable.right = self.isBlackBtn.left - TSScaleW(15);
    }
}
-(UIButton *)isBlackBtn
{
    if (!_isBlackBtn) {
        _isBlackBtn = [TSWLTools allocButtonTitle:@"拉黑" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor image:nil frame:CGRectMake(_commentsBtn.right, _commentsBtn.top, TSScaleW(60), TSScaleW(30)) sel:@selector(isBlackBtn:) taget:self];
        [_isBlackBtn setBorderWithWidth:0.5 andColor:kMainTxtColor];
        _isBlackBtn.centerY = _dateLable.centerY;
        _isBlackBtn.right = _dateLable.right;
    }
    return _isBlackBtn;
}
-(void)isBlackBtn:(UIButton *)sender
{
    !self.isBlackBlock?:self.isBlackBlock();
}

@end
